﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CsharpServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            InitConfig();
        }

        public void AddLog(string msg)
        {
            this.listBox1.Items.Add(msg);
        }

        public void ClearLog()
        {
            this.listBox1.Items.Clear();
        }

        protected override void OnClosed(EventArgs e)
        {
            AppConfig.singleton.SaveConfig();
            base.OnClosed(e);
        }

        private void InitConfig()
        {
            this.textBox1.Text = AppConfig.singleton.TcpPort;
            this.textBox2.Text = AppConfig.singleton.UdpPort;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            NetWorkMgr.singleton.Start();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            TextBox box = sender as TextBox;
            AppConfig.singleton.TcpPort = box.Text;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            NetWorkMgr.singleton.Stop();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            TextBox box = sender as TextBox;
            AppConfig.singleton.UdpPort = box.Text;
        }

    }
}
